/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package AutoIncrementClient;

import org.apache.thrift.TException;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TFramedTransport;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;
import org.apache.thrift.transport.TTransportException;

/**
 *
 * @author thuongnh
 */
public class AutoIncrementEnvoker {

    private static TTransport transport;
    private static TProtocol protocol;
    private static AutoIncrementService.Client client;

    private static void init() {
        try {
            Registry.init("backend.properties");
            transport = new TFramedTransport(new TSocket(Registry.get("AutoIncrementHost"), Integer.valueOf(Registry.get("AutoIncrementPort"))));
            protocol = new TBinaryProtocol(transport);
            client = new AutoIncrementService.Client(protocol);
            transport.open();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    public static synchronized AutoIncrementService.Client getApi() {
        if (client == null) {
            init();
        }
        return client;
    }

}
